<template>
  <el-dialog
    v-model="isShow"
    :title="handle.name + name"
    width="800px"
    :close-on-click-modal="false"
    @close="handleClose"
  >
    <el-form class="dialog-form" label-width="100px">
      <el-row :gutter="20">
        <el-col :xs="24">
          <el-form-item label="名称：">
            <el-input v-model="form.publicName" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :xs="24">
          <el-form-item label="键：">
            <el-input v-model="form.publicKey" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :xs="24">
          <el-form-item label="值：">
            <el-input v-model="form.publicValue" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :xs="24">
          <el-form-item label="状态：">
            <el-radio-group v-model="form.status" placeholder="请选择">
              <el-radio v-for="(item,index) in optionData.statusType" :key="index" :label="item.id">{{item.name}}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :xs="24">
          <el-form-item label="类型：">
            <el-select v-model="form.systemFlag" placeholder="请选择" clearable style="width:100%">
              <el-option v-for="(item,index) in optionData.dictType" :key="index" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="isShow = false">取消</el-button>
        <el-button type="primary" :loading="btnLoading" @click="toSubmit">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import {ElMessage, ElMessageBox} from 'element-plus'
import { ref, reactive, getCurrentInstance, nextTick } from 'vue';
import { useAddEdit } from '/@/assets/compositionFn/addEdit';
const obj = {
  api: '/api/admin/param',
  initForm:{
    id: null,
    publicName: null,
    publicKey: null,
    publicValue: null,
    status: '0',
    systemFlag: null,
  },
};
let {isShow, btnLoading, handle, optionData, form, init, returnInfo, handleClose, submitForm} = useAddEdit(obj);
const emit = defineEmits(['confirm']);
const {proxy} :any = getCurrentInstance();
const prop = defineProps({
  name: {
    type: String,
  }
});
watch(isShow,(newVal, oldVal) => {
  if(newVal){
    //弹窗后的其他操作
    let info = returnInfo();
  }
});
const verifyForm = ()=>{
  if(!proxy.$verify.null(form.publicName, '请填写名称')){
    return false;
  }
  if(!proxy.$verify.null(form.publicKey, '请填写键')){
    return false;
  }
  if(!proxy.$verify.null(form.publicValue, '请填写值')){
    return false;
  }
  if(!proxy.$verify.null(form.systemFlag, '请选择类型')){
    return false;
  }
  return true;
};
const toSubmit = ()=>{
  if(!verifyForm()){
    return;
  }
  submitForm().then(res => {
    emit('confirm');
  });
  
}
defineExpose({
  init,
})
</script>

<style>

</style>